<!--
 * @Author: Bennty
 * @Date: 2024-12-17 16:04:03
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-12-18 15:57:37
 * @Description: 请填写简介
-->
<template>
    <el-dialog :model-value="props.visible" title="审核加急" width="30%" @close="handleClose">
        <el-form ref="formRef" :model="formData" label-width="120px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="制单员：">{{ props.orderDetails.createByName }}</el-form-item>
                    <el-form-item label="销售单号：">{{ props.orderDetails.saleOrderCode }}</el-form-item>
                    <el-form-item label="申请加急日期：">{{ applyInfo.applyDate }}</el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="制单日期：">{{ props.orderDetails.createTime }}</el-form-item>
                    <el-form-item label="交货日期：">{{ props.orderDetails.deliveryDate }}</el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="申请加急原因：">{{ applyInfo.applyReason }}</el-form-item>
            <el-form-item label="审核建议" prop="approvalProposal">
                <el-input type="textarea" v-model="formData.approvalProposal" placeholder="请输入"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleClickPass" >通过</el-button>
                <el-button type="danger" @click="handleClickReject">拒绝</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { getUrgentApplyByBussinessApi, examineUrgentApi } from '@/api/sj/productManagement/customizedOrder';

const props = defineProps<{
    visible: boolean,
    orderDetails: any,
}>();
const emits = defineEmits(['close', 'submit']);
const formRef = ref<FormInstance>();
const formData = ref({
    approvalProposal: undefined
});
const applyInfo = ref<any>({});

watch(()=>[props.visible,props.orderDetails],async ([newVisible, newData])=>{
    if(newVisible){
        const { code, data } = await getUrgentApplyByBussinessApi(newData.id);
        if(code == 200){
            applyInfo.value = data;
        };
    };
},{deep: true});

const handleClickPass = async() => {
    const submitData = {
        ...formData.value,
        businessId: props.orderDetails.id,
        approvalStatus: 1,
        id: applyInfo.value.id
    };
    const {code} = await examineUrgentApi(submitData);
    if(code == 200){
        emits('submit', true);
        handleClose();
    }else{
        emits('submit', false);
    }
};

const handleClickReject = async() => {
    const submitData = {
        ...formData.value,
        businessId: props.orderDetails.id,
        approvalStatus: 2,
        id: applyInfo.value.id
    };
    const {code} = await examineUrgentApi(submitData);
    if(code == 200){
        emits('submit', true);
        handleClose();
    }else{
        emits('submit', false);
    }
};

const handleClose = () => {
    formRef.value?.resetFields();
    emits('close')
};
</script>

<style scoped>

</style>